package com.sise.aio和bio和nio.nio.nio的buffer学习;

import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.CharacterCodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.nio.charset.CharsetEncoder;

/**
 * 字符集的学习
 * @author idea
 * @data 2019/1/20
 */
public class Test3 {
    public static void main(String[] args) throws CharacterCodingException {
        Charset cs1=Charset.forName("UTF8");
        //获取编码器
        CharsetEncoder cs=cs1.newEncoder();


        //获取解码器
        CharsetDecoder cd=cs1.newDecoder();
        CharBuffer cbuf=CharBuffer.allocate(1024);
        cbuf.put("哈萨克就的哈尽快送达");
        cbuf.flip();

        ByteBuffer byteBuffer=cs.encode(cbuf);

        for(int i=0;i<byteBuffer.limit();i++){
            System.out.print((char)byteBuffer.get());
        }
        byteBuffer.flip();
    }
}
